package com.xiaoai.generic;

import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
import java.util.ArrayList;

/**
 * @Author
 * @Date 2021-09-08 00:50
 */
public class myTest {
    public static void main(String[] args) throws NoSuchMethodException, IllegalAccessException, InvocationTargetException, InstantiationException {
        // 泛型擦除
//        ArrayList<Integer> intList = new ArrayList<>();
//        ArrayList<String> strList = new ArrayList<>() ;
//
//        System.out.println(intList.getClass().getSimpleName());   // ArrayList
//        System. out.println(strList.getClass().getSimpleName ()); // ArrayList
//
//        System. out. println(intList.getClass() == strList.getClass()); // true


//        ArrayList<String>[] listArr1 = new ArrayList<>[5];         //报错
//        ArrayList<String>[] listArr2 = new ArrayList<String>[5];   //报错
        ArrayList[] list = new ArrayList[5];
        ArrayList<String>[] listArr3 = list;  //不报错

        ArrayList<Integer> intList = new ArrayList<>();
        intList.add(100);
        list[0] = intList;
        System.out.println(listArr3[0].get(0)); // 类型转换异常，因为存入Integer类型 取的时候用泛型String取


//        // 使用泛型
//        Class<Person> personClass = Person.class;
//        Constructor<Person> constructor = personClass.getConstructor();
//        Person person = constructor.newInstance();
        // 不使用泛型
        Class personClass = Person.class;
        Constructor constructor = personClass.getConstructor();
        Object person = constructor.newInstance();


    }
}